package oc_mongo

import (
	"context"
	"log"
	"oc_saas/internal/glo"
	"os"

	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

type ocMongo struct{}

// 初始化mongo
func (o *ocMongo) initMongo() *mongo.Client {
	client := options.Client().ApplyURI("mongodb://" + glo.OC_CONF.Mongo.User + ":" + glo.OC_CONF.Mongo.Password + "@" + glo.OC_CONF.Mongo.Addr + ":" + glo.OC_CONF.Mongo.Port + "/?authSource=admin")
	mongoClient, err := mongo.Connect(context.TODO(), client)
	if err != nil {
		log.Fatal(err)
		os.Exit(0)
	}
	err = mongoClient.Ping(context.TODO(), nil)
	if err != nil {
		log.Fatal(err)
		os.Exit(0)
	}
	return mongoClient
}

var OCMongoApp = new(ocMongo)
